﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace BDS3M.Admin.Controls
{
    public partial class AddPoster : System.Web.UI.UserControl
    {
        public string filePathPoster;

        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnAddPoster_Click(object sender, EventArgs e)
        {

            int nextid = Convert.ToInt32(DAL.DCollector.DBCollector.Instance.getNextID("tbl_Poster", "Poster_ID"));
            if (txtLink.Text != "")
            {
                if (fulImagePoster.HasFile)
                {
                    if (LIB.Validate.CheckFileType(fulImagePoster.FileName))
                    {

                        int idnextposter = nextid + 1;
                        string linkimage = fulImagePoster.FileName;
                        LIB.Validate saveimage = new LIB.Validate();
                        saveimage.ThayDoiKichThuocAnh(Server.MapPath("/Resources/Images/Images-Poster/"), linkimage, 940, fulImagePoster.PostedFile.InputStream);
                        filePathPoster = "/Resources/Images/Images-Poster/" + fulImagePoster.FileName;
                        string value = "" + idnextposter + ",N'" + txtTieuDe.Text + "',N'" + txtPlace.Text + "','" + filePathPoster + "','" + txtLink.Text + "',N'"+txtTitle.Text+"',N'"+txtSize.Text+"','" + DateTime.Now.ToString() + "'";
                        List<string> values = new List<string>();
                        values.Add(value);
                        DAL.DCollector.DBCollector.Instance.StoredProcedureInsertByRows("tbl_Poster", "insertonerow", values, false);
                        Response.Redirect("/Admin/Index.aspx?panel=5&sub=4");


                    }
                    else
                    {
                        Response.Write("<script>alert('Chỉ có thể upload file(.jpg,.png,.jpeg)')</script>");
                    }
                }
                else
                {
                    Response.Write("<script>alert('Vui lòng upload ảnh poster...')</script>");
                }
            }
            else
            {
                Response.Write("<script>alert('Vui lòng nhập link liên kết...')</script>");
            }

        }
    }
}